import { createRouter, createWebHashHistory } from 'vue-router'
//导入跳转路由组件
//Admin端
import StudentLogin from '../components/StudentLogin.vue'
import StudentContain from '../components/StudentContain.vue'
//导入5功能页面
import StudentClassesManagement from '../components/StudentClassesManagement.vue'
import StudentExaminationManagement from '../components/StudentExaminationManagement.vue'
import StudentInfoManagement from '../components/StudentInfoManagement.vue'
import StudentScoreManagement from '../components/StudentScoreManagement.vue'
import StudentSubjectManagement from '../components/StudentSubjectManagement.vue'
import StudentClassesInfo from '../components/StudentClassesInfo.vue'
import StudentClassesNumber from '../components/StudentClassesNumber.vue'
import StudentInfoManagemtnShow from '../components/StudentInfoManagemtnShow.vue'
import component from 'element-plus/es/components/tree-select/src/tree-select-option.mjs'
import StudentInfoManagmentAlter from '../components/StudentInfoManagmentAlter.vue'
//路由编写
import {studentStateStore} from '../store/StudentInfo.js'

const router = createRouter({
    history: createWebHashHistory(),
    routes: [
        //页面路由
        {
            path: '/',
            components: {
                //登录页面
                StudentRouter: StudentLogin
            },

        },
        {
            path: "/login",
            components: {
                //登录页面
                StudentRouter: StudentLogin
            }
        },
        {
            path: '/page',
            components: {
                //登录之后的页面
                StudentRouter: StudentContain

            },
            children: [
                {
                    path: "/page/classes",
                    components: {
                        PageRouter: StudentClassesManagement
                    },

                    children: [
                        {
                            path: "/page/classes/info",
                            components: {
                                PageClassesRouter: StudentClassesInfo
                            }

                        },
                        {
                            path: "/page/classes/student",
                            components: {
                                PageClassesRouter: StudentClassesNumber
                            }

                        }
                    ]

                },
                {
                    path: "/page/info",
                    components: {
                        PageRouter: StudentInfoManagement
                    },
                    children: [
                        {
                            path: "/page/info/student/show",
                            components: {
                                PageStudentInfoRouter: StudentInfoManagemtnShow
                            }
                        },
                        {
                            path: "/page/info/student/alter",
                            components: {
                                PageStudentInfoRouter: StudentInfoManagmentAlter
                            }
                        }

                    ]
                },
                {
                    path: "/page/examination",
                    components: {
                        PageRouter: StudentExaminationManagement
                    }
                },
                {
                    path: "/page/score",
                    components: {
                        PageRouter: StudentScoreManagement
                    }
                },
                {
                    path: "/page/subject",
                    components: {
                        PageRouter: StudentSubjectManagement
                    }
                }
            ]


        }
    ]
})
//路由控制页面的跳转
router.beforeEach(
    (to, from, next) => {
        const student = studentStateStore();
        //路由跳转
        if (to.path == "/login" || to.path == "/") {
            //登录页面放行
            next();
        }
        if (to.path == "/page" ||
            to.path == "/page/classes" ||
            to.path == "/page/classes/info" ||
            to.path == "/page/classes/student" ||
            to.path == "/page/info" ||
            to.path == "/page/info/student/show" ||
            to.path == "/page/info/student/alter" ||
            to.path == "/page/examination" ||
            to.path == "/page/score" ||
            to.path == "/page/subject" 

        ) {
            if (student.getterStudentstudentLoginState == 1) {
                next()
            }
        }


    }
)


export default router;//路由